package com.easy.controller;

import com.easy.bean.ClassificationBean;
import com.easy.bean.UserBean;
import com.easy.service.ClassificationService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("classification")
public class ClassificationController {
    @Autowired
    ClassificationService clasService;
    @PostMapping
    public Result add(@RequestBody ClassificationBean cla){
        ClassificationBean cla_data = clasService.add(cla);
        return Result.success(cla_data);
    }
    @PutMapping
    public Result edit(@RequestBody ClassificationBean cla){
        return Result.success(clasService.edit(cla));
    }
    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id){
        if(clasService.del(id)==0){
            return Result.success("删除失败");
        }
        return Result.success("删除成功");
    }
    @GetMapping("list")
    public Result list(ClassificationBean cla){
        Object list = clasService.list(cla);
        System.out.println(cla);
        System.out.println(list);
        return Result.success(list);
    }
    @GetMapping("page")
    public Result page(Page page, ClassificationBean clas){
        clasService.page(page, clas);
        return Result.success(page);
    }
}
